package MathCore;

import MathCore.Real;

public class CircularArray extends Object
{
	private Real elements [];
	private int entryPoint = 0;
	
	public CircularArray(int len)
	{
		elements = new Real [len];
		for(int i = 0; i<len; i++) elements[i] = new Real();
	}
	
	public void addToEnd(Real num)
	{
		elements[entryPoint % elements.length].assign(num);
		entryPoint++;
	}
	
	public void reset()
	{
		entryPoint = 0;
	}
	
	public void addToStart(Real num)
	{
		entryPoint--;
		if(entryPoint < 0 ) entryPoint += elements.length;
		
		elements[entryPoint % elements.length].assign(num);
	}

	public Real get(int pos)
	{
		if(pos < 0 || pos > elements.length) return null;
		return elements[(pos+entryPoint) % elements.length];
	}
	
	public int lenght()
	{
		return elements.length;
	}
	
}
